package FanShe3;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class TestUser {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<?> userClass = Class.forName("FanShe3.User");
        Object o = userClass.newInstance();
        System.out.println("o = " + o);

        //通过反射的对象访问构造器
        Constructor<?> constructor = userClass.getConstructor(String.class);
        Object hsp = constructor.newInstance("hsp");
        System.out.println("hsp = " + hsp);

        Constructor<?> constructor1 = userClass.getDeclaredConstructor(int.class, String.class);
        constructor1.setAccessible(true);
        Object user2 = constructor1.newInstance(100, "ddd");
        System.out.println("user2 = " + user2);


    }
}
